GPS4IC demonstration - Visualization

Visualize the output of the demonstration

In [1]:
def configure_plotly_browser_state():
  import IPython
  display(IPython.core.display.HTML('''
        <script src="/static/components/requirejs/require.js"></script>
        <script>
          requirejs.config({
            paths: {
              base: '/static/base',
              plotly: 'https://cdn.plot.ly/plotly-1.5.1.min.js?noext',
            },
          });
        </script>
        '''))
In [2]:
import pandas as pd
from scipy import stats
pd.set_option('display.max_colwidth', -1) 
import matplotlib.pyplot as plt
import numpy as np
import os
import re
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))

%matplotlib inline

from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.figure_factory as ff
init_notebook_mode(connected=True)
import plotly.graph_objs as go


from plotly.graph_objs import Contours, Histogram2dContour, Marker, Scatter


colors = dict(Conflict = 'rgb(220, 0, 0)',
              Colon_cancer_a_c = 'rgb(60, 60, 60)',
              Colon_cancer = 'rgb(0, 0, 220)',
              Parkinson = 'rgb(0, 220, 0)')
c:\users\hong_sun\pycharmprojects\workspace\venv\lib\site-packages\ipykernel_launcher.py:3: FutureWarning: Passing a negative integer is deprecated in version 1.0 and will not be supported in future version. Instead, use None to not limit the column width.
  This is separate from the ipykernel package so we can avoid doing imports until

At T0, a patient is coming for treatment of Parkinson disease

GMT: Tuesday, February 6, 2018 2:50:41 PM

Path Generation

4 possible paths are generated by the demonstration-execution notebook

In [3]:
pd.read_csv('../path/parkinson-answer-t0.csv', sep=',', encoding = 'utf-8')
Out[3]:
PATH DURATION COST BELIEF COMFORT UPDRS_SCORE
0 ("take_pill_Levodopa" "take_pill_Levodopa") P120DT0H0M0.0S 28.18 0.64 0.64 9.0
1 ("take_pill_Levodopa" "take_pill_Pramipexol") P120DT0H0M0.0S 113.80 0.64 0.72 9.2
2 ("take_pill_Pramipexol" "take_pill_Levodopa") P120DT0H0M0.0S 113.80 0.64 0.72 9.2
3 ("take_pill_Pramipexol" "take_pill_Pramipexol") P120DT0H0M0.0S 199.42 0.64 0.81 9.4

Manually select one path

Path 1 is selected from the 4 paths displayed before

In [4]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)

df_path = pd.read_csv('../path/aggreagatedPath-plot-t0.csv', sep=',', encoding = 'utf-8')
df = [dict(Task=df_path.action_name[0], Start=df_path.start_time[0], Finish=df_path.end_time[0], Resource=df_path.map_name[0])]
i=1
while i < len(df_path):
    df.append( dict(Task=df_path.action_name[i], Start=df_path.start_time[i], Finish=df_path.end_time[i], Resource=df_path.map_name[i]) )
    i+=1

fig = ff.create_gantt(df, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson')
fig['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))
iplot(fig, show_link=False)

At T1, the first action finishes, the patient got an updated data, perform path validation

GMT: Saturday, April 7, 2018 2:52:21 PM

Scenario a , the UPDRSScore remains the same. Predicted that the path no longer succeeds

In [5]:
!eye --nope ../data/data-parkinson-t1-a.ttl ../data/t2.ttl ../parkinson/gps-desc.n3  ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q
#Processed by EYE v20.0910.0008 josd
eye --nope ../data/data-parkinson-t1-a.ttl ../data/t2.ttl ../parkinson/gps-desc.n3 ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q
EYE v20.0910.0008 josd
SWI-Prolog version 8.0.3
starting 62 [msec cputime] 159 [msec walltime]
GET file:///d:/github/gps4icdemo/data/data-parkinson-t1-a.ttl SC=14
GET file:///d:/github/gps4icdemo/data/t2.ttl SC=1
GET file:///d:/github/gps4icdemo/parkinson/gps-desc.n3 SC=3
GET file:///d:/github/gps4icdemo/parkinson/score-calculation.n3 SC=1
GET file:///d:/github/gps4icdemo/path/aggreagatedpath-t0.n3 SC=1
GET file:///d:/github/gps4icdemo/engine/gps-plugin-validation.n3 SC=11
GET file:///d:/github/gps4icdemo/parkinson/gps-goal-parkinson.n3q SC=1
networking 31 [msec cputime] 335 [msec walltime]
reasoning 16 [msec cputime] 4 [msec walltime]
2021-02-14T15:39:17.497Z in=32 out=0 ent=1 step=2 brake=4 inf=208846 sec=0.109 inf/sec=1916018

#eye --nope ../data/data-parkinson-t1-a.ttl ../data/t2.ttl ../parkinson/gps-desc.n3 ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q

@prefix sct: <http://snomed.info/id/>.
@prefix data: <http://josd.github.io/eye/reasoning/gps/data#>.
@prefix care: <http://josd.github.io/eye/reasoning/gps/care#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>.
@prefix gps: <http://josd.github.io/eye/reasoning/gps/gps-schema#>.
@prefix action: <http://josd.github.io/eye/reasoning/gps/action#>.
@prefix : <http://josd.github.io/eye/reasoning#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix medication: <http://josd.github.io/eye/reasoning/gps/medication#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix prolog: <http://eulersharp.sourceforge.net/2003/03swap/prolog#>.
@prefix func: <http://www.w3.org/2007/rif-builtin-function#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.


#2021-02-14T15:39:17.497Z in=32 out=0 ent=1 step=2 brake=4 inf=208846 sec=0.109 inf/sec=1916018
#ENDS

Scenario b , the UPDRSScore drops by 1.5. Predicted that the remaining path would leads to satisfaction of the goal

In [6]:
!eye --nope ../data/data-parkinson-t1-b.ttl ../data/t2.ttl ../parkinson/gps-desc.n3  ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q
#Processed by EYE v20.0910.0008 josd
#eye --nope ../data/data-parkinson-t1-b.ttl ../data/t2.ttl ../parkinson/gps-desc.n3 ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q

@prefix sct: <http://snomed.info/id/>.
@prefix data: <http://josd.github.io/eye/reasoning/gps/data#>.
@prefix care: <http://josd.github.io/eye/reasoning/gps/care#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>.
@prefix gps: <http://josd.github.io/eye/reasoning/gps/gps-schema#>.
@prefix action: <http://josd.github.io/eye/reasoning/gps/action#>.
@prefix : <http://josd.github.io/eye/reasoning#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix medication: <http://josd.github.io/eye/reasoning/gps/medication#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix prolog: <http://eulersharp.sourceforge.net/2003/03swap/prolog#>.
@prefix func: <http://www.w3.org/2007/rif-builtin-function#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.

data:patient_1 gps:path ((((action:take_pill_Levodopa 1517928741 1523112741.0) gps:start 1517928741 {data:patient_1 care:updrs_score 12}) ((action:take_pill_Levodopa 1517928741 1523112741.0) gps:end 1523112741.0 {data:patient_1 care:updrs_score 10.5}) ((action:take_pill_Pramipexol 1523112741.0 1528296741.0) gps:start 1523112741.0 {data:patient_1 care:updrs_score 10.5}) (action:take_pill_Pramipexol gps:end 1528296741.0 {data:patient_1 care:updrs_score 9.2})) 10368000.0 199.42 0.6400000000000001 0.81 (9.2)).

#2021-02-14T15:39:18.099Z in=32 out=1 ent=2 step=4 brake=4 inf=211618 sec=0.140 inf/sec=1511557
#ENDS

eye --nope ../data/data-parkinson-t1-b.ttl ../data/t2.ttl ../parkinson/gps-desc.n3 ../parkinson/score-calculation.n3 ../path/aggreagatedPath-t0.n3 ../engine/gps-plugin-validation.n3 --query ../parkinson/gps-goal-parkinson.n3q
EYE v20.0910.0008 josd
SWI-Prolog version 8.0.3
starting 78 [msec cputime] 139 [msec walltime]
GET file:///d:/github/gps4icdemo/data/data-parkinson-t1-b.ttl SC=14
GET file:///d:/github/gps4icdemo/data/t2.ttl SC=1
GET file:///d:/github/gps4icdemo/parkinson/gps-desc.n3 SC=3
GET file:///d:/github/gps4icdemo/parkinson/score-calculation.n3 SC=1
GET file:///d:/github/gps4icdemo/path/aggreagatedpath-t0.n3 SC=1
GET file:///d:/github/gps4icdemo/engine/gps-plugin-validation.n3 SC=11
GET file:///d:/github/gps4icdemo/parkinson/gps-goal-parkinson.n3q SC=1
networking 62 [msec cputime] 195 [msec walltime]
reasoning 0 [msec cputime] 5 [msec walltime]
2021-02-14T15:39:18.099Z in=32 out=1 ent=2 step=4 brake=4 inf=211618 sec=0.140 inf/sec=1511557

At T3, the patient adds a new path to treat colon cancer

GMT: Thursday, April 12, 2018 2:50:33 PM

Path Generation

Scenario A : Patient has blocking colon

In [7]:
pd.read_csv('../path/colon-cancer-answer-t3-a.csv', sep=',', encoding = 'utf-8')
Out[7]:
PATH DURATION COST BELIEF COMFORT METASTASIS_RISK 5YR_SURVIVAL_RATE NON_TOXICITY 5YR_LOCAL_RELAPSE_RISK
0 ("surgery_colon_cancer" "Adjuvant_chemoradiotherapy") P85DT0H0M0.0S 43585.0 0.81 0.2 0.02 0.92 0.57 0.16

Scenario B : Patient does not have blocking colon

In [8]:
pd.read_csv('../path/colon-cancer-answer-t3-b.csv', sep=',', encoding = 'utf-8')
Out[8]:
PATH DURATION COST BELIEF COMFORT METASTASIS_RISK 5YR_SURVIVAL_RATE NON_TOXICITY 5YR_LOCAL_RELAPSE_RISK
0 ("Neoadjuvant_chemoradiotherapy" "surgery_colon_cancer") P55DT0H0M0.0S 35097.0 0.81 0.25 0.02 0.92 0.6935 0.06
1 ("surgery_colon_cancer" "Adjuvant_chemoradiotherapy") P85DT0H0M0.0S 43585.0 0.81 0.20 0.02 0.92 0.5700 0.16

Combinning paths

In [9]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)


df_path_a = pd.read_csv('../path/aggreagatedPath-plot-t3-a.csv', sep=',', encoding = 'utf-8')
df_a = [dict(Task=df_path_a.action_name[0], Start=df_path_a.start_time[0], Finish=df_path_a.end_time[0], Resource=df_path_a.map_name[0])]
i=1
while i < len(df_path_a):
    df_a.append( dict(Task=df_path_a.action_name[i], Start=df_path_a.start_time[i], Finish=df_path_a.end_time[i], Resource=df_path_a.map_name[i]) )
    i+=1
fig_a = ff.create_gantt(df_a, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson-Colon-Cancer-Scenario-A-with-blocking-colon')
fig_a['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))
iplot(fig_a, show_link=False)
In [10]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)

df_path_b = pd.read_csv('../path/aggreagatedPath-plot-t3-b.csv', sep=',', encoding = 'utf-8')
df_b = [dict(Task=df_path_b.action_name[0], Start=df_path_b.start_time[0], Finish=df_path_b.end_time[0], Resource=df_path_b.map_name[0])]
i=1
while i < len(df_path_b):
    df_b.append( dict(Task=df_path_b.action_name[i], Start=df_path_b.start_time[i], Finish=df_path_b.end_time[i], Resource=df_path_b.map_name[i]) )
    i+=1

fig_b = ff.create_gantt(df_b, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson-Colon-Cancer-Scenario-B-without-blocking-colon')
fig_b['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))
iplot(fig_b, show_link=False)

Alert detection

In [11]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)

conflict_action_a = pd.read_csv('../path/detected-conflict-t3-a.csv', sep=',', encoding = 'utf-8')

df_a_alert=df_a.copy()
df_a_alert.append( dict(Task=conflict_action_a.action_name[0], Start=conflict_action_a.start_time[0], Finish=conflict_action_a.end_time[0], Resource=conflict_action_a.map_name[0]) )


fig_a_alert = ff.create_gantt(df_a_alert, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson-Colon-Cancer-Scenario-A-with-blocking-colon')
fig_a_alert['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))
iplot(fig_a_alert, show_link=False)
In [12]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)

conflict_action_b = pd.read_csv('../path/detected-conflict-t3-b.csv', sep=',', encoding = 'utf-8')
    
df_b_alert=df_b.copy()    
df_b_alert.append( dict(Task=conflict_action_b.action_name[0], Start=conflict_action_b.start_time[0], Finish=conflict_action_b.end_time[0], Resource=conflict_action_b.map_name[0]) )


fig_b_alert = ff.create_gantt(df_b_alert, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson-Colon-Cancer-Scenario-B-without-blocking-colon')
fig_b_alert['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))

iplot(fig_b_alert, show_link=False)

Add executional details of adjuvant chemoradiotherapy

In [13]:
configure_plotly_browser_state()
init_notebook_mode(connected=False)

adjuvant_chemoradiotherapy_a = pd.read_csv('../path/path_adjuvant_chemoradiotherapy.csv', sep=',', encoding = 'utf-8')

df_a_details=df_a_alert.copy()

j=0
while j < len(adjuvant_chemoradiotherapy_a):
    df_a_details.append( dict(Task=adjuvant_chemoradiotherapy_a.action_name[j], Start=adjuvant_chemoradiotherapy_a.start_time[j], Finish=adjuvant_chemoradiotherapy_a.end_time[j], Resource=adjuvant_chemoradiotherapy_a.map_name[j]) )
    j+=1

fig_a_details = ff.create_gantt(df_a_details, colors=colors, index_col='Resource', show_colorbar=True,  title='Path-Parkinson-Colon-Cancer-Scenario-A-with-blocking-colon')
fig_a_details['layout'].update(autosize=False, width=800, height=600, margin=dict(l=200))
iplot(fig_a_details, show_link=False)
In [ ]:
 

Demo done, thanks for watching!

In [ ]: